package com.bumptech.glide.manager;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import o.FragmentManager;
import o.rp;
import o.yh;
import o.yr;

public class SupportRequestManagerFragment extends Fragment {
    private final Set<SupportRequestManagerFragment> ˊ;
    private final yh ˋ;
    @Nullable
    private rp ˎ;
    @Nullable
    private SupportRequestManagerFragment ˏ;
    private final yr ॱ;
    @Nullable
    private Fragment ॱॱ;

    class e implements yr {
        final /* synthetic */ SupportRequestManagerFragment ˋ;

        e(SupportRequestManagerFragment supportRequestManagerFragment) {
            this.ˋ = supportRequestManagerFragment;
        }

        @NonNull
        public Set<rp> ˋ() {
            Set<SupportRequestManagerFragment> ʽˊ = this.ˋ.ʽˊ();
            Set<rp> hashSet = new HashSet(ʽˊ.size());
            for (SupportRequestManagerFragment supportRequestManagerFragment : ʽˊ) {
                if (supportRequestManagerFragment.ʼᐝ() != null) {
                    hashSet.add(supportRequestManagerFragment.ʼᐝ());
                }
            }
            return hashSet;
        }

        public String toString() {
            return super.toString() + "{fragment=" + this.ˋ + "}";
        }
    }

    public SupportRequestManagerFragment() {
        this(new yh());
    }

    @VisibleForTesting
    @SuppressLint({"ValidFragment"})
    public SupportRequestManagerFragment(@NonNull yh yhVar) {
        this.ॱ = new e(this);
        this.ˊ = new HashSet();
        this.ˋ = yhVar;
    }

    public void ˋ(@Nullable rp rpVar) {
        this.ˎ = rpVar;
    }

    @NonNull
    public yh ॱ() {
        return this.ˋ;
    }

    @Nullable
    public rp ʼᐝ() {
        return this.ˎ;
    }

    @NonNull
    public yr ʾॱ() {
        return this.ॱ;
    }

    private void ˎ(SupportRequestManagerFragment supportRequestManagerFragment) {
        this.ˊ.add(supportRequestManagerFragment);
    }

    private void ˋ(SupportRequestManagerFragment supportRequestManagerFragment) {
        this.ˊ.remove(supportRequestManagerFragment);
    }

    @NonNull
    Set<SupportRequestManagerFragment> ʽˊ() {
        if (this.ˏ == null) {
            return Collections.emptySet();
        }
        if (equals(this.ˏ)) {
            return Collections.unmodifiableSet(this.ˊ);
        }
        Set hashSet = new HashSet();
        for (SupportRequestManagerFragment supportRequestManagerFragment : this.ˏ.ʽˊ()) {
            if (ˎ(supportRequestManagerFragment.ʽᐝ())) {
                hashSet.add(supportRequestManagerFragment);
            }
        }
        return Collections.unmodifiableSet(hashSet);
    }

    public void ˊ(@Nullable Fragment fragment) {
        this.ॱॱ = fragment;
        if (fragment != null && fragment.ॱˊ() != null) {
            FragmentManager ˏ = ˏ(fragment);
            if (ˏ != null) {
                ˏ(fragment.ॱˊ(), ˏ);
            }
        }
    }

    @Nullable
    private static FragmentManager ˏ(@NonNull Fragment fragment) {
        while (fragment.ˈ() != null) {
            fragment = fragment.ˈ();
        }
        return fragment.ॱᐝ();
    }

    @Nullable
    private Fragment ʽᐝ() {
        Fragment ˈ = ˈ();
        return ˈ != null ? ˈ : this.ॱॱ;
    }

    private boolean ˎ(@NonNull Fragment fragment) {
        Fragment ʽᐝ = ʽᐝ();
        while (true) {
            Fragment ˈ = fragment.ˈ();
            if (ˈ == null) {
                return false;
            }
            if (ˈ.equals(ʽᐝ)) {
                return true;
            }
            fragment = fragment.ˈ();
        }
    }

    private void ˏ(@NonNull Context context, @NonNull FragmentManager juVar) {
        ˊʻ();
        this.ˏ = Glide.ˎ(context).ʻ().ˊ(context, juVar);
        if (!equals(this.ˏ)) {
            this.ˏ.ˎ(this);
        }
    }

    private void ˊʻ() {
        if (this.ˏ != null) {
            this.ˏ.ˋ(this);
            this.ˏ = null;
        }
    }

    public void ॱ(Context context) {
        super.ॱ(context);
        FragmentManager ˏ = ˏ(this);
        if (ˏ != null) {
            try {
                ˏ(ॱˊ(), ˏ);
            } catch (Throwable e) {
                if (Log.isLoggable("SupportRMFragment", 5)) {
                    Log.w("SupportRMFragment", "Unable to register fragment with root", e);
                }
            }
        } else if (Log.isLoggable("SupportRMFragment", 5)) {
            Log.w("SupportRMFragment", "Unable to register fragment with root, ancestor detached");
        }
    }

    public void ˎ() {
        super.ˎ();
        this.ॱॱ = null;
        ˊʻ();
    }

    public void ag_() {
        super.ag_();
        this.ˋ.ˎ();
    }

    public void ʼ() {
        super.ʼ();
        this.ˋ.ˏ();
    }

    public void ˎˎ() {
        super.ˎˎ();
        this.ˋ.ॱ();
        ˊʻ();
    }

    public String toString() {
        return super.toString() + "{parent=" + ʽᐝ() + "}";
    }
}
